package com.shushan.pages.bean;

import com.android.net.bean.NetBaseBean;
import com.shushan.base.Constants;
import com.shushan.exam.bean.ExerciseBean;
import com.shushan.exam.bean.ExerciseResultBean;
import com.shushan.exam.bean.PaperBean;
import com.shushan.mixedexam.bean.MutiExerciseBean;
import com.shushan.mixedexam.oralcalculation.bean.OralCalculateExerciseBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ExerciseRecordDetailsBean
 * @Desciption: //练习记录详情bean
 * @author: zhangshihao
 * @date: 2018-04-24
 */
public class ExerciseRecordDetailsBean extends NetBaseBean {

    public List<MutiExerciseBean> chineseExerciseBeans = new ArrayList<>();
    public List<MutiExerciseBean> mathExerciseBeans = new ArrayList<>();
    public List<MutiExerciseBean> englishExerciseBeans = new ArrayList<>();

    public List<MutiExerciseBean> exerciseBeans = new ArrayList<>();
    public PaperInfoBean paperInfoBean;

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        if(jsonObject != null){
            JSONArray chineseArray = jsonObject.optJSONArray(Constants.SUBJECT_CHINESE_ID+"");
            JSONArray mathArray = jsonObject.optJSONArray(Constants.SUBJECT_MACH_ID+"");
            JSONArray englishArray = jsonObject.optJSONArray(Constants.SUBJECT_ENGLISH_ID+"");

            if((chineseArray != null && chineseArray.length() > 0) || (mathArray != null && mathArray.length() > 0)
                    || (englishArray != null && englishArray.length() > 0)){
                if(chineseArray != null && chineseArray.length() > 0) {
                    for (int i = 0; i < chineseArray.length(); i++) {
                        MutiExerciseBean bean = new MutiExerciseBean();
                        bean.initByJson((JSONObject) chineseArray.get(i));
                        chineseExerciseBeans.add(bean);
                    }

                    if (mathArray != null && mathArray.length() > 0) {
                        for (int i = 0; i < mathArray.length(); i++) {
                            MutiExerciseBean bean = new MutiExerciseBean();
                            bean.initByJson((JSONObject) mathArray.get(i));
                            mathExerciseBeans.add(bean);
                        }
                    }

                    if (englishArray != null && englishArray.length() > 0) {
                        for (int i = 0; i < englishArray.length(); i++) {
                            MutiExerciseBean bean = new MutiExerciseBean();
                            bean.initByJson((JSONObject) englishArray.get(i));
                            englishExerciseBeans.add(bean);
                        }
                    }
                }
            }else{
                JSONArray paperArray = jsonObject.optJSONArray("paper");
                if(paperArray != null && paperArray.length() > 0) {
                    for (int i=0;i<paperArray.length();i++) {
                        MutiExerciseBean bean = new MutiExerciseBean();
                        bean.initByJson((JSONObject)paperArray.get(i));
                        exerciseBeans.add(bean);
                    }
                }
            }

            paperInfoBean = new PaperInfoBean();
            JSONObject erBeanObj = jsonObject.optJSONObject("paper_info");
            paperInfoBean.initByJson(erBeanObj);
        }
    }
}
